Assembly Language
© Copyright Brian Brown, 1988-2000. All rights reserved.
| Notes | Home Page |


ASSEMBLY LANGUAGE PROGRAMMING, Part 2
home page prev page next page


ASSEMBLER DIRECTIVES
As mentioned previously, assembler directives are instructions to the assembler, and are not translated into machine instructions. The use of directives gives the programmer some control over the operation of the assembler, increasing flexibility in the way programs are written. The following is a list of the common pseudo-ops.


SAMPLE PROGRAM FOR MC6802 USING CRS8
The following source file has been named MC6802.ASM


		 	CPU	6802	; 6802 processor
		 	HOF	MOT 	; Motorola Records 
			ORG	0100H 	; Start of Data
	Source:		DFB	'Hello and Welcome'
	Length:		EQU	$ - Source ;Length of Source
	Destin:		DFS	Length	; Buffer which has same 
					; length as Source
			ORG	0120H	; Start of Code
	Entry:		LDX	#Source	; Point Index Reg to 
					; Source string
			LDAB	#Length	; Number of characters to move
	Loop:		LDAA	0,X
			STAA	Length,X
			INX
			DECB
			BNE	Loop
	Fin:		JMP	Fin
			END	Entry

This program is assembled by typing the following command


	CRS8 MC6802

It is not necessary to type the extension .ASM, and CRS8 will produce two output files.


 MC6802.PRN 	; a list file showing the code generated
 MC6802.HEX	; the record file for downloading to the 
		; target system or Eprom programmer

The listing file MC6802.PRN looks like


	C:6802.TBL	CPU	6802			; 6802 processor
	C:6802.HEX	HOF	MOT			; Motorola Records

	0100		ORG	0100H 			; Start of Data
	0100 48656C6C6F	Source:	DFB	'Hello and Welcome'
	0011 = 		Length: EQU	$ - Source	; Length of Source
	0111 		Destin:	DFS	Length 		; Buffer which has same
							; length as Source 
	0120 			ORG	0120H 		; Start of Code 
	0120 CE0100 	Entry:	LDX	#Source 	; Point Index Reg to 
							; Source string 
	0123 C611 		LDAB	#Length 	; Number of characters
							; to move 
	0125 A600 	Loop:	LDAA 	0,X
	0127 A711		STAA	Length,X
	0129 08			INX
	012A 5A			DECB
	012B 26F8 		BNE 	Loop 
	012D 7E012D 	Fin: 	JMP 	Fin
	0130 			END 	Entry

The first column is the address, the second the instructions or data, and then the mnemonics and comments. This listing is used by the programmer to verify that the assembler has produced the correct instructions and data at the correct addresses. We can clearly see that it has correctly interpreted the address of Source in the statement LDX #Source as the bytes CE 0100.

The record format file MC6802.HEX looks like


	S00D0000433A363830322E48455892
	S113010048656C6C6F20616E642057656C636F6D1D
	S10401106585
	S1130120CE0100C611A600A711085A26F87E012D9F
	S9030120DB

The format of a motorola record is


	Digit
	 0,1		Record Type = S0, S1 or S9
	 2,3		Number of bytes in Record which includes the load address and checksum bytes
	 4,5,6,7	Load Address 8 to n-2 Data or coded instructions
	 n-1 to n	Checksum value

	 The S0 record identifies the program name
	 The S1 record identifies the data and coded instructions
	 The S9 record identifies the program entry point
		 eg
		S1 04 0110 65 85
		^  ^   ^   ^  ^checksum
		^  ^   ^   ^   data
		^  ^   ^       load address
		^  ^           number of bytes in record
		^              record type

The file is then downloaded to the target system.


ELEMENTARY DATA TYPES
Most programming languages support data types like characters and integers. At the processor level, some instructions support integer type operations such as multiply or divide (except 6802).The programmer is responsible for keeping track of data types. The processor treats all data the same, and if the program goes astray, can interpret data as instructions and vise versa.

Lets look at how elementary data is represented by the programmer for use in assembly language programs.


Typical Array Operations
The following routines are typical of functions which are performed on character based arrays.


ARRAY INDEX CALCULATIONS
This refers to calculating the address of a specified element within an array. In single dimensioned arrays, this is equivalent to


	BASE_ADDRESS + (ELEMENT_NUMBER * NUMBER_OF_BYTES_PER_ELEMENT)

In multi-dimensioned arrays, this is equivalent to


	BASE_ADDRESS + (Col_Num + (Row_num * Num_Col_per_row)) * Num_Bytes_per_Element)


home page prev page next page
© Copyright Brian Brown, 1988-2000. All rights reserved.